package com.lyeducation.controllers.video;

import com.lyeducation.security.config.SecurityPrincipalContext;
import com.lyeducation.util.aLiYunOss.CallbackServerUtil;
import com.lyeducation.util.controllerUtil.JsonConstans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("sysOss/{mId}")
public class SysOssController {

    @Autowired
    private CallbackServerUtil callbackServerUtil;

    @GetMapping("requestPolicyCallback")
    public void requestPolicyCallback(HttpServletRequest request, HttpServletResponse response) {
        if (SecurityPrincipalContext.checkHasAdminOrGeneralAdminRole()) {
            callbackServerUtil.requestPolicyCallback(request, response);
        } else {
            throw new RuntimeException(JsonConstans.ERR_NOTVALID_AUTH.toString());
        }
    }

    @PostMapping("callback")
    public void callback(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        callbackServerUtil.callback(request, response);
    }
}
